const sql = require("../../mysql");

module.exports = async ctx => {
  try {
    if (ctx.request.userRole !== "admin") {
      ctx.body = {
        code: -1,
        msg: "没有权限"
      };
      return;
    }
    let { idArray, status } = ctx.request.body;

    await sql.User.update(
      { status: !status },
      {
        where: {
          id: {
            [sql.Op.in]: idArray
          }
        }
      }
    );

    ctx.body = {
      code: 0,
      msg: "更新成功"
    };
  } catch (error) {
    console.log(error);
    ctx.response.status = 200;

    ctx.body = {
      code: -1,
      msg: error.errors ? error : error.errors[0].message
    };
  }
};
